package com.yaorange.jk.service.impl;

import com.yaorange.jk.dao.BaseDao;
import com.yaorange.jk.entity.PackingList;
import com.yaorange.jk.service.PackingListService;
import com.yaorange.jk.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class PackingListServiceImpl implements PackingListService {
@Autowired
private BaseDao<PackingList,String> packingListDao;

@Override
public Pagination findPage(Pagination page) {
return packingListDao.pageByHql("from PackingList",page.getPageNo(),page.getPageSize());
}

@Override
public List<PackingList> findAll() {
    return packingListDao.getListByHQL("from PackingList");
    }

    @Override
    public void save(PackingList model) {
    	model.setState(0D);
    packingListDao.save(model);
    }

    @Override
    public void deleteById(String id) {
    packingListDao.deleteById(PackingList.class,id);
    }

    @Override
    public void update(PackingList model) {
    packingListDao.update(model);
    }

    @Override
    public PackingList findById(String id) {
    return packingListDao.get(PackingList.class,id);
    }

	@Override
	public void topacking(PackingList packingList) {
		packingList.setState(1d);
		packingListDao.update(packingList);
	}

	@Override
	public Pagination findPage(Pagination page,double state) {
		// TODO Auto-generated method stub
		return packingListDao.pageByHql("from PackingList p where p.state=?",page.getPageNo(),page.getPageSize(),state);
	}

	@Override
	public void cancel(PackingList packingList) {
		packingList.setState(0d);
		packingListDao.update(packingList);
	}
    }
